/****************************************************************************
 *
 *  ALi (Shanghai) Corporation, All Rights Reserved. 2008 Copyright (C)
 *
 *  File: media_control.c
 *
 *  Description: .
 *
 *  History:
 *  Date            Author  		Version  Comment
 *  ====            ======  		=======  =======
 *  1.  2009.01.09  Sharon Zhang				edit for mediaplayer 3.0
 *
 ****************************************************************************/
#include <sys_config.h>

#ifdef USB_MP_SUPPORT
#include <types.h>
#include <basic_types.h>
#include <mediatypes.h>
#include <api/libc/printf.h>
#include <api/libc/string.h>
#include <osal/osal.h>
#include <api/libmp/media_player_api.h>
#include <api/libmp/pe.h>
#include <api/libfs2/statvfs.h>
#ifndef NEW_DEMO_FRAME
#include <api/libpub29/lib_hde.h>
#else
#include <api/libpub/lib_hde.h>
#endif

#include <api/libosd/osd_lib.h>
#include <hld/pan/pan_dev.h>
#include <hld/decv/decv.h>

#include "osdobjs_def.h"
#include "images.id"
#include "string.id"
#include "osd_config.h"

#include "control.h"
#include "menus_root.h"
#include "win_com.h"
#include "win_com_popup.h"
#include "win_com_list.h"
#include "win_media.h"
#include "copper_common/com_api.h"
#include <api/libmp/mp_subtitle_api.h>
#include <ali2dto3d/ALi_pic_2dto3d.h>

extern font_subt_t *font_array_1bit_subt[];

#ifdef _INVW_JUICE  //v0.1.4
// An alternative media player callback handler which may optionally be set
// to handle events outside of the native player
static mp_callback_func mp_alternative_cb = 0;
#endif
///////////////////////////////////////
// start of title & help UI definition
///////////////////////////////////////
extern CONTAINER  usb_title_con;
extern BITMAP 	  usb_title_bmp1;
extern TEXT_FIELD usb_title_txt1;
extern BITMAP 	  usb_title_bmp2;
extern TEXT_FIELD usb_title_txt2;
extern BITMAP 	  usb_title_bmp3;
extern TEXT_FIELD usb_title_txt3;
extern BITMAP 	  usb_title_bmp4;
extern TEXT_FIELD usb_title_txt4;
extern BITMAP 	  usb_title_line1;
extern BITMAP 	  usb_title_line2;
extern BITMAP 	  usb_title_line3;

extern CONTAINER  usb_help_win;
extern CONTAINER  usb_help_con;
extern BITMAP 	  usb_help1_btn1;
extern BITMAP 	  usb_help1_btn2;
extern BITMAP 	  usb_help1_btn3;
extern BITMAP 	  usb_help1_btn4;
extern BITMAP 	  usb_help1_btn5;
extern TEXT_FIELD usb_help1_txt1;
extern TEXT_FIELD usb_help1_txt2;
extern TEXT_FIELD usb_help1_txt3;
extern TEXT_FIELD usb_help1_txt4;
extern TEXT_FIELD usb_help1_txt5;

extern BITMAP	  usb_help2_btn1;
extern BITMAP	  usb_help2_btn2;
extern BITMAP 	  usb_help2_btn3;
extern BITMAP 	  usb_help2_btn4;
extern BITMAP 	  usb_help2_btn5;
extern TEXT_FIELD usb_help2_txt1;
extern TEXT_FIELD usb_help2_txt2;
extern TEXT_FIELD usb_help2_txt3;
extern TEXT_FIELD usb_help2_txt4;
extern TEXT_FIELD usb_help2_txt5;

#if Maker_GUI_ON
#define TITLE_SH_IDX  WSTL_WIN_TITLE_YJ
#else
#define TITLE_SH_IDX  WSTL_WIN_TITLE_01_HD
#endif
#define TITLE_ICON1_SH	WSTL_MIX_BMP_HD
#define TITLE_TXT1_SH	WSTL_MIXBACK_IDX_01_8BIT//sharon WSTL_MP_TEXT_01_HD
#define TITLE_ICON2_SH	WSTL_MIX_BMP_HD
#define TITLE_TXT2_SH	WSTL_MIXBACK_IDX_04_8BIT//sharon WSTL_MP_TEXT_02_HD
#define TITLE_TXT2_GRY	WSTL_MIXBACK_IDX_07_8BIT//sharon WSTL_MP_TEXT_02_HD

#define HLP_WIN_SH_IDX  WSTL_MP_WIN_BOTTOM_HD
#define HLP_CON_SH_IDX  WSTL_MP_HELP_HD

#ifndef SD_UI
#if Maker_GUI_TEST
#define TITLE_L		74
#define TITLE_T		5//FL_W_T
#define TITLE_W		866
#define TITLE_H		68
#define TITLE_GAP	210

#define TITLE_ICON_W		0//40//96
#define TITLE_ICON_H		0//40//64
#define TITLE_TXT_W		156
#define TITLE_TXT_H		40
#else
#define TITLE_L		74
#define TITLE_T		5//FL_W_T
#define TITLE_W		866
#define TITLE_H		68
#define TITLE_GAP	210

#define TITLE_ICON_W		56//40//96
#define TITLE_ICON_H		54//40//64
#define TITLE_TXT_W		100
#define TITLE_TXT_H		40
#endif

#define TITLE_ICON1_L		(TITLE_L+40)
#define TITLE_ICON1_T		(TITLE_T)
#define TITLE_TXT1_L		(TITLE_ICON1_L+TITLE_ICON_W)
#define TITLE_TXT1_T		(TITLE_ICON1_T+8)

#define TITLE_ICON2_L		(TITLE_ICON1_L+TITLE_GAP)//(TITLE_L+280)
#define TITLE_ICON2_T		(TITLE_T)
#define TITLE_TXT2_L		(TITLE_ICON2_L+TITLE_ICON_W)
#define TITLE_TXT2_T		(TITLE_ICON2_T+8)

#define TITLE_ICON3_L		(TITLE_ICON2_L+TITLE_GAP)//(TITLE_L+460)
#define TITLE_ICON3_T		(TITLE_T)
#define TITLE_TXT3_L		(TITLE_ICON3_L+TITLE_ICON_W)
#define TITLE_TXT3_T		(TITLE_ICON3_T+8)

#define TITLE_ICON4_L		(TITLE_ICON3_L+TITLE_GAP)//(TITLE_L+640)
#define TITLE_ICON4_T		(TITLE_T)
#define TITLE_TXT4_L		(TITLE_ICON4_L+TITLE_ICON_W)
#define TITLE_TXT4_T		(TITLE_ICON4_T+8)

#define TITLE_LINE_L		(TITLE_L+TITLE_GAP)
#define TITLE_LINE_T		TITLE_T
#define TITLE_LINE_W		8
#define TITLE_LINE_H		54

#define HLPWIN_L TITLE_L
#define HLPWIN_T (TITLE_T+TITLE_H+440)//(LSTCON_T + LSTCON_H)
#define HLPWIN_W TITLE_W
#define HLPWIN_H 100

#define HLPCON_L (HLPWIN_L+14)
#define HLPCON_T (HLPWIN_T+6)//(LSTCON_T + LSTCON_H)
#define HLPCON_W (HLPWIN_W-28)
#define HLPCON_H (HLPWIN_H-20)

#define HELP_T1 (HLPCON_T+4)
#define HELP_H 36
#define HELP_T2 (HELP_T1+HELP_H)
#define HELP_ICON_W 36
#define HELP_TXT_W 	130
#define HELP_L (HLPCON_L+6)
#else
#define TITLE_L		17
#define TITLE_T		12//FL_W_T
#define TITLE_W		570
#define TITLE_H		45
#define TITLE_GAP	110

#define TITLE_ICON_W		43//40//96
#define TITLE_ICON_H		43//40//64
#define TITLE_TXT_W		100
#define TITLE_TXT_H		32

#define TITLE_ICON1_L		(TITLE_L+20)
#define TITLE_ICON1_T		(TITLE_T)
#define TITLE_TXT1_L		(TITLE_ICON1_L+TITLE_ICON_W)
#define TITLE_TXT1_T		(TITLE_ICON1_T+8)

#define TITLE_ICON2_L		(TITLE_ICON1_L+TITLE_GAP)//(TITLE_L+280)
#define TITLE_ICON2_T		(TITLE_T)
#define TITLE_TXT2_L		(TITLE_ICON2_L+TITLE_ICON_W)
#define TITLE_TXT2_T		(TITLE_ICON2_T+8)

#define TITLE_ICON3_L		(TITLE_ICON2_L+TITLE_GAP)//(TITLE_L+460)
#define TITLE_ICON3_T		(TITLE_T)
#define TITLE_TXT3_L		(TITLE_ICON3_L+TITLE_ICON_W)
#define TITLE_TXT3_T		(TITLE_ICON3_T+8)

#define TITLE_ICON4_L		(TITLE_ICON3_L+TITLE_GAP)//(TITLE_L+640)
#define TITLE_ICON4_T		(TITLE_T)
#define TITLE_TXT4_L		(TITLE_ICON4_L+TITLE_ICON_W)
#define TITLE_TXT4_T		(TITLE_ICON4_T+8)

#define TITLE_LINE_L		(TITLE_L+TITLE_GAP)
#define TITLE_LINE_T		TITLE_T
#define TITLE_LINE_W		0
#define TITLE_LINE_H		54

#define HLPWIN_L TITLE_L
#define HLPWIN_T (TITLE_T+TITLE_H+350)//(LSTCON_T + LSTCON_H)
#define HLPWIN_W TITLE_W
#define HLPWIN_H 75

#define HLPCON_L (HLPWIN_L+10)
#define HLPCON_T (HLPWIN_T+6)//(LSTCON_T + LSTCON_H)
#define HLPCON_W (HLPWIN_W-20)
#define HLPCON_H 58//(HLPWIN_H-20)

#define HELP_T1 (HLPCON_T+4)
#define HELP_H 24//36
#define HELP_T2 (HELP_T1+HELP_H)
#define HELP_ICON_W 26
#define HELP_TXT_W 	81
#define HELP_L (HLPCON_L+6)
#endif

struct mp_title_tab_resource
{
	UINT16	bmp_id;
	UINT16	str_id;
};

struct mp_help_item1_resource
{
	UINT16	bmp_id;
	UINT16	str_id;
};

struct mp_help_item2_resource
{
	char*	icon_txt;
	UINT16	str_id;
};

#define LDEF_TITLE_CON(root, varCon,nxtObj,l,t,w,h,conobj,focusID,allHilite)		\
    DEF_CONTAINER(varCon,root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, TITLE_SH_IDX,TITLE_SH_IDX,TITLE_SH_IDX,TITLE_SH_IDX,   \
    NULL,NULL,  \
    conobj, focusID,allHilite)

#define LDET_TITLE_BMP(root,varBmp,nxtObj,l,t,w,h,sh,icon)	\
  DEF_BITMAP(varBmp,&root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, sh,sh,sh,sh,   \
    NULL,NULL,  \
    C_ALIGN_LEFT | C_ALIGN_VCENTER,0,0,icon)

#if Maker_GUI_TEST
#define LDEF_TITLE_TXT(root,varTxt,nxtObj,l,t,w,h,sh,resID,str)		\
    DEF_TEXTFIELD(varTxt,&root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, sh,sh,sh,sh,   \
    NULL,NULL,  \
    C_ALIGN_CENTER | C_ALIGN_VCENTER, 0,0,resID,str)
#else
#define LDEF_TITLE_TXT(root,varTxt,nxtObj,l,t,w,h,sh,resID,str)		\
    DEF_TEXTFIELD(varTxt,&root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, sh,sh,sh,sh,   \
    NULL,NULL,  \
    C_ALIGN_LEFT | C_ALIGN_VCENTER, 0,0,resID,str)
#endif    

#define LDEF_HLP_WIN(root, varCon,nxtObj,l,t,w,h,conobj)		\
    DEF_CONTAINER(varCon,root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, HLP_WIN_SH_IDX,HLP_WIN_SH_IDX,HLP_WIN_SH_IDX,HLP_WIN_SH_IDX,   \
    NULL,NULL,  \
    conobj, 1,1)

#define LDEF_HLP_CON(root, varCon,nxtObj,l,t,w,h,conobj)		\
    DEF_CONTAINER(varCon,&root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, HLP_CON_SH_IDX,HLP_CON_SH_IDX,HLP_CON_SH_IDX,HLP_CON_SH_IDX,   \
    NULL,NULL,  \
    conobj, 1,1)

#define LDET_HLP_BMP(root,varBmp,nxtObj,l,t,w,h)	\
  DEF_BITMAP(varBmp,&root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, WSTL_WIN_EPG_HELP_HD,WSTL_WIN_EPG_HELP_HD,WSTL_WIN_EPG_HELP_HD,WSTL_WIN_EPG_HELP_HD,   \
    NULL,NULL,  \
	C_ALIGN_CENTER| C_ALIGN_VCENTER, 0, 0,0)

#define LDEF_HLP_TXT(root,varTxt,nxtObj,l,t,w,h,resID,str)		\
    DEF_TEXTFIELD(varTxt,&root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, WSTL_WIN_EPG_HELP_HD,WSTL_WIN_EPG_HELP_HD,WSTL_WIN_EPG_HELP_HD,WSTL_MP_HELP_GRY,   \
    NULL,NULL,  \
    C_ALIGN_LEFT | C_ALIGN_VCENTER, 0,0,resID,str)

LDEF_TITLE_CON(NULL, usb_title_con, NULL,TITLE_L,TITLE_T,TITLE_W,TITLE_H,&usb_title_bmp1,1,1)
#if Maker_GUI_TEST
LDET_TITLE_BMP(usb_title_con, usb_title_bmp1, &usb_title_txt1, 	TITLE_ICON1_L, TITLE_ICON1_T, TITLE_ICON_W, TITLE_ICON_H, TITLE_ICON1_SH, NULL)
LDEF_TITLE_TXT(usb_title_con, usb_title_txt1, &usb_title_bmp2, 	TITLE_TXT1_L,  TITLE_TXT1_T,  TITLE_TXT_W,  TITLE_TXT_H,  TITLE_TXT1_SH,  RS_MP_MUSIC,NULL)
LDET_TITLE_BMP(usb_title_con, usb_title_bmp2, &usb_title_txt2, 	TITLE_ICON2_L, TITLE_ICON2_T, TITLE_ICON_W, TITLE_ICON_H, TITLE_ICON2_SH, NULL)
LDEF_TITLE_TXT(usb_title_con, usb_title_txt2, &usb_title_bmp3, 	TITLE_TXT2_L,  TITLE_TXT2_T,  TITLE_TXT_W,  TITLE_TXT_H,  TITLE_TXT2_SH,  RS_MP_IMAGE,NULL)
LDET_TITLE_BMP(usb_title_con, usb_title_bmp3, &usb_title_txt3, 	TITLE_ICON3_L, TITLE_ICON3_T, TITLE_ICON_W, TITLE_ICON_H, TITLE_ICON2_SH, NULL)
LDEF_TITLE_TXT(usb_title_con, usb_title_txt3, &usb_title_bmp4, 	TITLE_TXT3_L,  TITLE_TXT3_T,  TITLE_TXT_W,  TITLE_TXT_H,  TITLE_TXT2_SH,  RS_PVR,NULL)
LDET_TITLE_BMP(usb_title_con, usb_title_bmp4, &usb_title_txt4, 	TITLE_ICON4_L, TITLE_ICON4_T, TITLE_ICON_W, TITLE_ICON_H, TITLE_ICON2_SH, NULL)
LDEF_TITLE_TXT(usb_title_con, usb_title_txt4, &usb_title_line1, 			TITLE_TXT4_L,  TITLE_TXT4_T,  TITLE_TXT_W,  TITLE_TXT_H,  TITLE_TXT2_SH,  RS_MP_VIDEO,NULL)
#else
LDET_TITLE_BMP(usb_title_con, usb_title_bmp1, &usb_title_txt1, 	TITLE_ICON1_L, TITLE_ICON1_T, TITLE_ICON_W, TITLE_ICON_H, TITLE_ICON1_SH, IM_MEDIAPLAY_TOPBG_ICON_MUSIC)
LDEF_TITLE_TXT(usb_title_con, usb_title_txt1, &usb_title_bmp2, 	TITLE_TXT1_L,  TITLE_TXT1_T,  TITLE_TXT_W,  TITLE_TXT_H,  TITLE_TXT1_SH,  RS_MP_MUSIC,NULL)
LDET_TITLE_BMP(usb_title_con, usb_title_bmp2, &usb_title_txt2, 	TITLE_ICON2_L, TITLE_ICON2_T, TITLE_ICON_W, TITLE_ICON_H, TITLE_ICON2_SH, IM_MEDIAPLAY_TOPBG_ICON_PHOTO_S)
LDEF_TITLE_TXT(usb_title_con, usb_title_txt2, &usb_title_bmp3, 	TITLE_TXT2_L,  TITLE_TXT2_T,  TITLE_TXT_W,  TITLE_TXT_H,  TITLE_TXT2_SH,  RS_MP_IMAGE,NULL)
LDET_TITLE_BMP(usb_title_con, usb_title_bmp3, &usb_title_txt3, 	TITLE_ICON3_L, TITLE_ICON3_T, TITLE_ICON_W, TITLE_ICON_H, TITLE_ICON2_SH, IM_MEDIAPLAY_TOPBG_ICON_RECORD_S)
LDEF_TITLE_TXT(usb_title_con, usb_title_txt3, &usb_title_bmp4, 	TITLE_TXT3_L,  TITLE_TXT3_T,  TITLE_TXT_W,  TITLE_TXT_H,  TITLE_TXT2_SH,  RS_PVR,NULL)
LDET_TITLE_BMP(usb_title_con, usb_title_bmp4, &usb_title_txt4, 	TITLE_ICON4_L, TITLE_ICON4_T, TITLE_ICON_W, TITLE_ICON_H, TITLE_ICON2_SH, IM_MEDIAPLAY_TOPBG_ICON_VIDEO_S)
LDEF_TITLE_TXT(usb_title_con, usb_title_txt4, &usb_title_line1, 			TITLE_TXT4_L,  TITLE_TXT4_T,  TITLE_TXT_W,  TITLE_TXT_H,  TITLE_TXT2_SH,  RS_MP_VIDEO,NULL)
#endif
LDET_TITLE_BMP(usb_title_con, usb_title_line1, &usb_title_line2, 	TITLE_LINE_L, TITLE_LINE_T, TITLE_LINE_W, TITLE_LINE_H, TITLE_ICON1_SH, IM_MEDIAPLAY_TITLELINE_01)
LDET_TITLE_BMP(usb_title_con, usb_title_line2, &usb_title_line3, 	TITLE_LINE_L+TITLE_GAP, TITLE_LINE_T, TITLE_LINE_W, TITLE_LINE_H, TITLE_ICON1_SH, IM_MEDIAPLAY_TITLELINE_01)
LDET_TITLE_BMP(usb_title_con, usb_title_line3, NULL, 	TITLE_LINE_L+TITLE_GAP*2, TITLE_LINE_T, TITLE_LINE_W, TITLE_LINE_H, TITLE_ICON1_SH, IM_MEDIAPLAY_TITLELINE_01)

LDEF_HLP_WIN(NULL, usb_help_win,NULL,HLPWIN_L,HLPWIN_T,HLPWIN_W,HLPWIN_H,&usb_help_con)
LDEF_HLP_CON(usb_help_win, usb_help_con,NULL,HLPCON_L,HLPCON_T,HLPCON_W,HLPCON_H,&usb_help1_btn1)
LDET_HLP_BMP(usb_help_con, usb_help1_btn1, &usb_help1_txt1,	HELP_L, HELP_T1, HELP_ICON_W, HELP_H)
LDEF_HLP_TXT(usb_help_con, usb_help1_txt1, &usb_help1_btn2,	HELP_L+HELP_ICON_W, HELP_T1, HELP_TXT_W, HELP_H, RS_COMMON_OK,NULL)
LDET_HLP_BMP(usb_help_con, usb_help1_btn2, &usb_help1_txt2,	HELP_L+1*(HELP_ICON_W+HELP_TXT_W), HELP_T1, HELP_ICON_W, HELP_H)
LDEF_HLP_TXT(usb_help_con, usb_help1_txt2, &usb_help1_btn3,	HELP_L+HELP_ICON_W+1*(HELP_ICON_W+HELP_TXT_W), HELP_T1, HELP_TXT_W, HELP_H, RS_COMMON_OK,NULL)
LDET_HLP_BMP(usb_help_con, usb_help1_btn3, &usb_help1_txt3,	HELP_L+2*(HELP_ICON_W+HELP_TXT_W), HELP_T1, HELP_ICON_W, HELP_H)
LDEF_HLP_TXT(usb_help_con, usb_help1_txt3, &usb_help1_btn4,	HELP_L+HELP_ICON_W+2*(HELP_ICON_W+HELP_TXT_W), HELP_T1, HELP_TXT_W, HELP_H, RS_COMMON_OK,NULL)
LDET_HLP_BMP(usb_help_con, usb_help1_btn4, &usb_help1_txt4,	HELP_L+3*(HELP_ICON_W+HELP_TXT_W), HELP_T1, HELP_ICON_W, HELP_H)
LDEF_HLP_TXT(usb_help_con, usb_help1_txt4, &usb_help1_btn5,	HELP_L+HELP_ICON_W+3*(HELP_ICON_W+HELP_TXT_W), HELP_T1, HELP_TXT_W, HELP_H, RS_COMMON_OK,NULL)
LDET_HLP_BMP(usb_help_con, usb_help1_btn5, &usb_help1_txt5,	HELP_L+4*(HELP_ICON_W+HELP_TXT_W), HELP_T1, HELP_ICON_W, HELP_H)
LDEF_HLP_TXT(usb_help_con, usb_help1_txt5, &usb_help2_btn1,	HELP_L+HELP_ICON_W+4*(HELP_ICON_W+HELP_TXT_W), HELP_T1, HELP_TXT_W, HELP_H, RS_COMMON_OK,NULL)

LDET_HLP_BMP(usb_help_con, usb_help2_btn1, &usb_help2_txt1,	HELP_L, HELP_T2, HELP_ICON_W, HELP_H)
LDEF_HLP_TXT(usb_help_con, usb_help2_txt1, &usb_help2_btn2,	HELP_L+HELP_ICON_W, HELP_T2, HELP_TXT_W, HELP_H, RS_COMMON_OK,NULL)
LDET_HLP_BMP(usb_help_con, usb_help2_btn2, &usb_help2_txt2,	HELP_L+1*(HELP_ICON_W+HELP_TXT_W), HELP_T2, HELP_ICON_W, HELP_H)
LDEF_HLP_TXT(usb_help_con, usb_help2_txt2, &usb_help2_btn3,	HELP_L+HELP_ICON_W+1*(HELP_ICON_W+HELP_TXT_W), HELP_T2, HELP_TXT_W, HELP_H, RS_COMMON_OK,NULL)
LDET_HLP_BMP(usb_help_con, usb_help2_btn3, &usb_help2_txt3,	HELP_L+2*(HELP_ICON_W+HELP_TXT_W), HELP_T2, HELP_ICON_W, HELP_H)
LDEF_HLP_TXT(usb_help_con, usb_help2_txt3, &usb_help2_btn4,	HELP_L+HELP_ICON_W+2*(HELP_ICON_W+HELP_TXT_W), HELP_T2, HELP_TXT_W, HELP_H, RS_COMMON_OK,NULL)
LDET_HLP_BMP(usb_help_con, usb_help2_btn4, &usb_help2_txt4,	HELP_L+3*(HELP_ICON_W+HELP_TXT_W), HELP_T2, HELP_ICON_W, HELP_H)
#ifndef SD_UI
LDEF_HLP_TXT(usb_help_con, usb_help2_txt4, &usb_help2_btn5,	HELP_L+HELP_ICON_W+3*(HELP_ICON_W+HELP_TXT_W), HELP_T2, HELP_TXT_W, HELP_H, RS_COMMON_OK,NULL)
#else
LDEF_HLP_TXT(usb_help_con, usb_help2_txt4, &usb_help2_btn5,	HELP_L+HELP_ICON_W+3*(HELP_ICON_W+HELP_TXT_W), HELP_T2, HELP_TXT_W+5, HELP_H, RS_COMMON_OK,NULL)
#endif
LDET_HLP_BMP(usb_help_con, usb_help2_btn5, &usb_help2_txt5,	HELP_L+4*(HELP_ICON_W+HELP_TXT_W), HELP_T2, HELP_ICON_W, HELP_H)
LDEF_HLP_TXT(usb_help_con, usb_help2_txt5, NULL,			HELP_L+HELP_ICON_W+4*(HELP_ICON_W+HELP_TXT_W), HELP_T2, HELP_TXT_W, HELP_H, RS_COMMON_OK,NULL)


//filelist title tab define
struct mp_title_tab_resource title_tab[] =
{
#if(defined SUPPORT_CAS9 && (!defined MEDIAPLAYER_SUPPORT))
	{0,		0},
    {0,		0},
    {0,		0},
    {IM_MEDIAPLAY_TOPBG_ICON_RECORD,		RS_PVR},

    {0,		0},
    {0,		0},
    {0,		0},
    {IM_MEDIAPLAY_TOPBG_ICON_RECORD_S,	RS_PVR},

    {0,	0},
    {0,	0},
    {0,	0},
    {IM_MEDIAPLAY_TOPBG_ICON_RECORD_GRAY,	RS_PVR},
#else
#if Maker_GUI_TEST
	{0,		RS_MP_MUSIC},
    {0,		RS_MP_IMAGE},
    {0,		RS_MP_VIDEO},
    {0,		RS_PVR},
    
    {0,		RS_MP_MUSIC},
    {0,		RS_MP_IMAGE},
    {0,		RS_MP_VIDEO},
    {0,	RS_PVR},
    
    {0,	RS_MP_MUSIC},
    {0,	RS_MP_IMAGE},
    {0,	RS_MP_VIDEO},
    {0,	RS_PVR},
#else
    {IM_MEDIAPLAY_TOPBG_ICON_MUSIC,		RS_MP_MUSIC},
    {IM_MEDIAPLAY_TOPBG_ICON_PHOTO,		RS_MP_IMAGE},
    {IM_MEDIAPLAY_TOPBG_ICON_VIDEO,		RS_MP_VIDEO},
    {IM_MEDIAPLAY_TOPBG_ICON_RECORD,		RS_PVR},

    {IM_MEDIAPLAY_TOPBG_ICON_MUSIC_S,		RS_MP_MUSIC},
    {IM_MEDIAPLAY_TOPBG_ICON_PHOTO_S,		RS_MP_IMAGE},
    {IM_MEDIAPLAY_TOPBG_ICON_VIDEO_S,		RS_MP_VIDEO},
    {IM_MEDIAPLAY_TOPBG_ICON_RECORD_S,	RS_PVR},

    {IM_MEDIAPLAY_TOPBG_ICON_MUSIC_GRAY,	RS_MP_MUSIC},
    {IM_MEDIAPLAY_TOPBG_ICON_PHOTO_GRAY,	RS_MP_IMAGE},
    {IM_MEDIAPLAY_TOPBG_ICON_VIDEO_GRAY,	RS_MP_VIDEO},
    {IM_MEDIAPLAY_TOPBG_ICON_RECORD_GRAY,	RS_PVR},
#endif
#endif    
};

#define HELPCNT	5

BITMAP *pHelp1Btn_icons[] =
{
	&usb_help1_btn1,
	&usb_help1_btn2,
	&usb_help1_btn3,
	&usb_help1_btn4,
	&usb_help1_btn5,
};

TEXT_FIELD *pHelp1Txt_ids[] =
{
	&usb_help1_txt1,
	&usb_help1_txt2,
	&usb_help1_txt3,
	&usb_help1_txt4,
	&usb_help1_txt5,
};

BITMAP *pHelp2Btn_icons[] =
{
	&usb_help2_btn1,
	&usb_help2_btn2,
	&usb_help2_btn3,
	&usb_help2_btn4,
	&usb_help2_btn5,
};

TEXT_FIELD *pHelp2Txt_ids[] =
{
	&usb_help2_txt1,
	&usb_help2_txt2,
	&usb_help2_txt3,
	&usb_help2_txt4,
	&usb_help2_txt5,
};

////////////////////
//music help define
struct mp_help_item1_resource  music_help1[] =
{
#if 1//ChengYu@20131001, change file list help icon
	{IM_MEDIAPLAY_HELPBUTTON_SWAP,	RS_MP_HELP_SWITCH},
    {IM_FILELIST_NUMBERBUTTON1,     RS_MP_PLAY_LIST},
    {IM_FILELIST_NUMBERBUTTON2,     RS_FAV},
    {IM_FILELIST_NUMBERBUTTON3,		RS_MP_FAV_ALL},
#else
    {IM_EPG_COLORBUTTON_RED,       RS_MP_PLAY_LIST},
    {IM_EPG_COLORBUTTON_GREEN,     RS_FAV},
    {IM_EPG_COLORBUTTON_YELLOW,    RS_MP_FAV_ALL},
    {IM_EPG_COLORBUTTON_BLUE,      RS_HELP_EDIT},
    {IM_MEDIAPLAY_HELPBUTTON_I,    0},
#endif
};
#define MUSIC_HELP1_CNT	(sizeof(music_help1)/sizeof(struct mp_help_item1_resource))

struct mp_help_item1_resource  music_help2[] =
{
#if 1//ChengYu@20131001, change file list help icon
	{IM_MEDIAPLAY_HELPBUTTON_EXIT,	RS_HELP_EXIT},
	{IM_FILELIST_NUMBERBUTTON4,		RS_HELP_EDIT},
    {IM_FILELIST_NUMBERBUTTON5,		RS_HELP_SORT},
    {IM_FILELIST_NUMBERBUTTON6,		RS_MP_REPEAT_MODE},
#else
    {IM_MEDIAPLAY_HELPBUTTON_SWAP,	RS_MP_HELP_SWITCH},
    {IM_MEDIAPLAY_HELPBUTTON_PIP,     RS_HELP_SORT},
    {IM_MEDIAPLAY_HELPBUTTON_AB,    	RS_MP_REPEAT_MODE},
    {IM_MEDIAPLAY_HELPBUTTON_EXIT,    RS_HELP_EXIT},
#endif    
};
#define MUSIC_HELP2_CNT	(sizeof(music_help2)/sizeof(struct mp_help_item1_resource))

////////////////////
//photo help define
struct mp_help_item1_resource  photo_help1[] =
{
#if 1//ChengYu@20131001, change file list help icon
	{IM_MEDIAPLAY_HELPBUTTON_SWAP,	RS_MP_HELP_SWITCH},
    {IM_FILELIST_NUMBERBUTTON1,		RS_MP_PLAY_LIST},
    {IM_FILELIST_NUMBERBUTTON2,		RS_FAV},
    {IM_FILELIST_NUMBERBUTTON3,		RS_MP_FAV_ALL},
#else
    {IM_EPG_COLORBUTTON_RED,       RS_MP_PLAY_LIST},
    {IM_EPG_COLORBUTTON_GREEN,     RS_FAV},
    {IM_EPG_COLORBUTTON_YELLOW,    RS_MP_FAV_ALL},
    {IM_EPG_COLORBUTTON_BLUE,      RS_HELP_EDIT},
    {IM_MEDIAPLAY_HELPBUTTON_I,    0},
#endif
};
#define PHOTO_HELP1_CNT	(sizeof(photo_help1)/sizeof(struct mp_help_item1_resource))

struct mp_help_item1_resource  photo_help2[] =
{
#if 1//ChengYu@20131001, change file list help icon
	{IM_MEDIAPLAY_HELPBUTTON_EXIT,	RS_HELP_EXIT},
	{IM_FILELIST_NUMBERBUTTON4,		RS_HELP_EDIT},
    {IM_FILELIST_NUMBERBUTTON5,		RS_HELP_SORT},
    {IM_FILELIST_NUMBERBUTTON6,		RS_GAME_SETUP},
    {IM_FILELIST_NUMBERBUTTON7,		RS_MP_HELP_MULTI_VIEW},
#else
    {IM_MEDIAPLAY_HELPBUTTON_SWAP,	RS_MP_HELP_SWITCH},
    {IM_MEDIAPLAY_HELPBUTTON_PIP,     RS_HELP_SORT},
    {IM_MEDIAPLAY_HELPBUTTON_AB,    	RS_GAME_SETUP},
    {IM_MEDIAPLAY_HELPBUTTON_MP,		RS_MP_HELP_MULTI_VIEW},
    {IM_MEDIAPLAY_HELPBUTTON_EXIT,    RS_HELP_EXIT},
#endif    
};
#define PHOTO_HELP2_CNT	(sizeof(photo_help2)/sizeof(struct mp_help_item1_resource))

////////////////////
//video help define
struct mp_help_item1_resource  video_help1[] =
{
#if 1//ChengYu@20131001, change file list help icon
	{IM_MEDIAPLAY_HELPBUTTON_SWAP,	RS_MP_HELP_SWITCH},
	{IM_FILELIST_NUMBERBUTTON1,		RS_HELP_EDIT},
	{IM_FILELIST_NUMBERBUTTON2,		RS_HELP_SORT},
	{IM_FILELIST_NUMBERBUTTON3,		RS_MP_REPEAT_MODE},
#else
//    {IM_EPG_COLORBUTTON_RED,       RS_MP_PLAY_LIST},
//    {IM_EPG_COLORBUTTON_GREEN,     RS_FAV},
//    {IM_EPG_COLORBUTTON_YELLOW,    RS_MP_FAV_ALL},
    {IM_EPG_COLORBUTTON_BLUE,      RS_HELP_EDIT},
    {IM_MEDIAPLAY_HELPBUTTON_I,    0},
#endif
};
#define VIDEO_HELP1_CNT	(sizeof(video_help1)/sizeof(struct mp_help_item1_resource))

struct mp_help_item1_resource  video_help2[] =
{
#if 1//ChengYu@20131001, change file list help icon
	{IM_MEDIAPLAY_HELPBUTTON_EXIT,	RS_HELP_EXIT},
#else
    {IM_MEDIAPLAY_HELPBUTTON_SWAP,	RS_MP_HELP_SWITCH},
    {IM_MEDIAPLAY_HELPBUTTON_PIP,     RS_HELP_SORT},
    {IM_MEDIAPLAY_HELPBUTTON_EXIT,    RS_HELP_EXIT},
    {IM_MEDIAPLAY_HELPBUTTON_AB,    	RS_MP_REPEAT_MODE},
#endif
};
#define VIDEO_HELP2_CNT	(sizeof(video_help2)/sizeof(struct mp_help_item1_resource))

////////////////////
//record help define
struct mp_help_item1_resource  record_help1[] =
{
#if 1//ChengYu@20131001, change file list help icon
	{IM_MEDIAPLAY_HELPBUTTON_SWAP,	RS_MP_HELP_SWITCH},
	{IM_FILELIST_NUMBERBUTTON1,		RS_HELP_RENAME},
	{IM_FILELIST_NUMBERBUTTON2,		RS_SORT_LOCK},
	{IM_FILELIST_NUMBERBUTTON3,		RS_HELP_DELETE},
#else
    {IM_EPG_COLORBUTTON_RED,       RS_HELP_RENAME},
    {IM_EPG_COLORBUTTON_GREEN,     RS_SORT_LOCK},
    {IM_EPG_COLORBUTTON_YELLOW,    RS_HELP_DELETE},
//    {IM_EPG_COLORBUTTON_BLUE,      RS_DISEQC12_ADVANCE},
    {IM_MEDIAPLAY_HELPBUTTON_I,    0},
#endif
};

#define RECORD_HELP1_CNT	(sizeof(record_help1)/sizeof(struct mp_help_item1_resource))

struct mp_help_item1_resource  record_help2[] =
{
#if 1//ChengYu@20131001, change file list help icon
	{IM_MEDIAPLAY_HELPBUTTON_EXIT,	RS_HELP_EXIT},
#else
#if((!defined SUPPORT_CAS9)|| (defined MEDIAPLAYER_SUPPORT))
    {IM_MEDIAPLAY_HELPBUTTON_SWAP,	RS_MP_HELP_SWITCH},
#endif
//    {IM_MEDIAPLAY_HELPBUTTON_PIP,     RS_HELP_SORT},
    {IM_MEDIAPLAY_HELPBUTTON_EXIT,    RS_HELP_EXIT},
#endif
};
#define RECORD_HELP2_CNT	(sizeof(record_help2)/sizeof(struct mp_help_item1_resource))

///////////////////////////////
//music&photo edit help define
struct mp_help_item1_resource  edit_help[] =
{	//Martin@20150105
    {IM_EPG_COLORBTN_RED,       RS_HELP_RENAME},
    {IM_EPG_COLORBTN_GREEN,     RS_HELP_COPY},
    {IM_EPG_COLORBTN_YELLOW,    RS_HELP_DELETE},
    {IM_EPG_COLORBTN_BLUE,      RS_MP_HELP_MAKE_FOLDER},
    //{IM_MEDIAPLAY_HELPBUTTON_I,    0},
};

#define EDIT_HELP_CNT	(sizeof(edit_help)/sizeof(struct mp_help_item1_resource))

///////////////////////////////
//record advance help define
struct mp_help_item1_resource  advance_help[] =
{
    {IM_EPG_COLORBUTTON_RED,       RS_HELP_COPY},
//    {IM_EPG_COLORBUTTON_GREEN,     RS_MP_HELP_MAKE_FOLDER},
    //{IM_MEDIAPLAY_HELPBUTTON_I,    0},
};
#define ADVANCE_HELP_CNT	(sizeof(advance_help)/sizeof(struct mp_help_item1_resource))

struct mp_help_item1_resource* helps1[] =
{
	music_help1,
	photo_help1,
	video_help1,
	record_help1,
};
UINT8 help_cnt1[] =
{
	MUSIC_HELP1_CNT,
	PHOTO_HELP1_CNT,
	VIDEO_HELP1_CNT,
	RECORD_HELP1_CNT,
};

struct mp_help_item1_resource* helps2[] =
{
	music_help2,
	photo_help2,
	video_help2,
	record_help2,
};
UINT8 help_cnt2[] =
{
	MUSIC_HELP2_CNT,
	PHOTO_HELP2_CNT,
	VIDEO_HELP2_CNT,
	RECORD_HELP2_CNT,
};

struct mp_help_item1_resource* edithelps[] =
{
	edit_help,
	edit_help,
	edit_help,
	advance_help,
};
UINT8 edithelp_cnt[] =
{
	EDIT_HELP_CNT,
	EDIT_HELP_CNT,
	EDIT_HELP_CNT,
	ADVANCE_HELP_CNT,
};

void win_set_mp_pvr_title(UINT8 main_title, TITLE_TYPE title_type)
{
	BITMAP *pBmp;
	TEXT_FIELD *pTxt;
	struct mp_title_tab_resource* titleitem;
	TITLE_TYPE type;
	POBJECT_HEAD pObj;

	if(main_title == 1)
	{
		type = title_type;
		titleitem = &title_tab[type];
		pBmp = &usb_title_bmp1;
		OSD_SetBitmapContent(pBmp, titleitem->bmp_id);
		pTxt = &usb_title_txt1;
		OSD_SetTextFieldContent(pTxt,STRING_ID,titleitem->str_id);

		type = (title_type+1)%TITLE_NUMBER;
		titleitem = &title_tab[type+TITLE_NUMBER];
		pBmp = &usb_title_bmp2;
		OSD_SetBitmapContent(pBmp, titleitem->bmp_id);
		pTxt = &usb_title_txt2;
		OSD_SetTextFieldContent(pTxt,STRING_ID,titleitem->str_id);
     	OSD_SetColor(pTxt, TITLE_TXT2_SH, TITLE_TXT2_SH, TITLE_TXT2_SH, TITLE_TXT2_SH);

		type = (title_type+2)%TITLE_NUMBER;
		titleitem = &title_tab[type+TITLE_NUMBER];
		pBmp = &usb_title_bmp3;
		OSD_SetBitmapContent(pBmp, titleitem->bmp_id);
		pTxt = &usb_title_txt3;
		OSD_SetTextFieldContent(pTxt,STRING_ID,titleitem->str_id);
     	OSD_SetColor(pTxt, TITLE_TXT2_SH, TITLE_TXT2_SH, TITLE_TXT2_SH, TITLE_TXT2_SH);

		type = (title_type+3)%TITLE_NUMBER;
		titleitem = &title_tab[type+TITLE_NUMBER];
		pBmp = &usb_title_bmp4;
		OSD_SetBitmapContent(pBmp, titleitem->bmp_id);
		pTxt = &usb_title_txt4;
		OSD_SetTextFieldContent(pTxt,STRING_ID,titleitem->str_id);
     	OSD_SetColor(pTxt, TITLE_TXT2_SH, TITLE_TXT2_SH, TITLE_TXT2_SH, TITLE_TXT2_SH);
	}
	else
	{
		type = title_type;
		titleitem = &title_tab[type];
		pBmp = &usb_title_bmp1;
		OSD_SetBitmapContent(pBmp, titleitem->bmp_id);
		pTxt = &usb_title_txt1;
		OSD_SetTextFieldContent(pTxt,STRING_ID,titleitem->str_id);

		type = (title_type+1)%TITLE_NUMBER;
		titleitem = &title_tab[type+TITLE_NUMBER*2];
		pBmp = &usb_title_bmp2;
		OSD_SetBitmapContent(pBmp, titleitem->bmp_id);
		pTxt = &usb_title_txt2;
		OSD_SetTextFieldContent(pTxt,STRING_ID,titleitem->str_id);
     	OSD_SetColor(pTxt, TITLE_TXT2_GRY, TITLE_TXT2_GRY, TITLE_TXT2_GRY, TITLE_TXT2_GRY);

		type = (title_type+2)%TITLE_NUMBER;
		titleitem = &title_tab[type+TITLE_NUMBER*2];
		pBmp = &usb_title_bmp3;
		OSD_SetBitmapContent(pBmp, titleitem->bmp_id);
		pTxt = &usb_title_txt3;
		OSD_SetTextFieldContent(pTxt,STRING_ID,titleitem->str_id);
     	OSD_SetColor(pTxt, TITLE_TXT2_GRY, TITLE_TXT2_GRY, TITLE_TXT2_GRY, TITLE_TXT2_GRY);

		type = (title_type+3)%TITLE_NUMBER;
		titleitem = &title_tab[type+TITLE_NUMBER*2];
		pBmp = &usb_title_bmp4;
		OSD_SetBitmapContent(pBmp, titleitem->bmp_id);
		pTxt = &usb_title_txt4;
		OSD_SetTextFieldContent(pTxt,STRING_ID,titleitem->str_id);
        	OSD_SetColor(pTxt, TITLE_TXT2_GRY, TITLE_TXT2_GRY, TITLE_TXT2_GRY, TITLE_TXT2_GRY);
    }
    
}

void win_draw_mp_pvr_title(void)
{
	POBJECT_HEAD pObj;

	pObj = (POBJECT_HEAD)&usb_title_con;
	OSD_DrawObject((POBJECT_HEAD)pObj,C_UPDATE_ALL);
}

//for example
//win_set_mpflielist_help1(edithelps[TITLE_RECORD],edithelp_cnt[TITLE_RECORD]);
//win_set_mpflielist_help2(NULL,0);

static void win_set_mpflielist_help1(struct mp_help_item1_resource *helpinfo,UINT8 item_count)
{
	UINT8 i = 0;
	BITMAP* pBmp;
	TEXT_FIELD* pTxt;
	struct mp_help_item1_resource* helpitem;

	for(i = 0; i < item_count;i++)
	{
		helpitem = &helpinfo[i];

		pBmp = pHelp1Btn_icons[i];
		OSD_SetBitmapContent(pBmp, helpitem->bmp_id);

		pTxt = pHelp1Txt_ids[i];
		OSD_SetTextFieldContent(pTxt,STRING_ID,helpitem->str_id);
	}

	if(item_count<HELPCNT)//some help item not show
	{
		for(i=item_count; i<HELPCNT; i++)
		{
			pBmp = pHelp1Btn_icons[i];
			OSD_SetBitmapContent(pBmp, 0);

			pTxt = pHelp1Txt_ids[i];
			OSD_SetTextFieldContent(pTxt,STRING_ID,0);
		}
	}

}

static void win_set_mpflielist_help2(struct mp_help_item1_resource *helpinfo,UINT8 item_count)
{
	UINT8 i = 0;
	BITMAP *pBtn;
	TEXT_FIELD *pTxt;
	struct mp_help_item1_resource* helpitem;

	for(i = 0; i < item_count;i++)
	{
		helpitem = &helpinfo[i];

		pBtn = pHelp2Btn_icons[i];
		OSD_SetBitmapContent(pBtn, helpitem->bmp_id);

		pTxt = pHelp2Txt_ids[i];
		OSD_SetTextFieldContent(pTxt,STRING_ID,helpitem->str_id);
	}

	if(item_count<HELPCNT)//some help item not show
	{
		for(i=item_count; i<HELPCNT; i++)
		{
			pBtn = pHelp2Btn_icons[i];
			OSD_SetBitmapContent(pBtn , 0);

			pTxt = pHelp2Txt_ids[i];
			OSD_SetTextFieldContent(pTxt,STRING_ID,0);
		}
	}
}

void win_set_mp_pvr_help_attr(UINT8 main_help, TITLE_TYPE title_type)
{
	POBJECT_HEAD pObj;
	UINT8 i = 0;
	TEXT_FIELD* pTxt;
	struct mp_help_item1_resource* helpitem;

	if(title_type == TITLE_RECORD)
	{
		pObj = (OBJECT_HEAD *)&g_win_record;
	}
	else
	{
		pObj = (OBJECT_HEAD *)&g_win_usb_filelist;
	}
	if(main_help == 1)
	{
		if(OSD_GetFocusID(pObj) == MP_DEVICE_ID)
		{
			switch(title_type)//ChengYu@20131001, change file list help icon
			{
			case TITLE_MUSIC:
				OSD_SetAttr(pHelp1Txt_ids[0], C_ATTR_ACTIVE);//switch
				OSD_SetAttr(pHelp1Txt_ids[1], C_ATTR_INACTIVE);//play list
				OSD_SetAttr(pHelp1Txt_ids[2], C_ATTR_INACTIVE);//fav
				OSD_SetAttr(pHelp1Txt_ids[3], C_ATTR_INACTIVE);//fav all
				OSD_SetAttr(pHelp1Txt_ids[4], C_ATTR_ACTIVE);

				OSD_SetAttr(pHelp2Txt_ids[0], C_ATTR_ACTIVE);//exit
				OSD_SetAttr(pHelp2Txt_ids[1], C_ATTR_INACTIVE);//edit
				OSD_SetAttr(pHelp2Txt_ids[2], C_ATTR_INACTIVE);//sort
				OSD_SetAttr(pHelp2Txt_ids[3], C_ATTR_INACTIVE);//repeat
				OSD_SetAttr(pHelp2Txt_ids[4], C_ATTR_ACTIVE);
				break;
			case TITLE_IMAGE:
				OSD_SetAttr(pHelp1Txt_ids[0], C_ATTR_ACTIVE);//switch
				OSD_SetAttr(pHelp1Txt_ids[1], C_ATTR_INACTIVE);//play list
				OSD_SetAttr(pHelp1Txt_ids[2], C_ATTR_INACTIVE);//fav
				OSD_SetAttr(pHelp1Txt_ids[3], C_ATTR_INACTIVE);//fav all
				OSD_SetAttr(pHelp1Txt_ids[4], C_ATTR_ACTIVE);

				OSD_SetAttr(pHelp2Txt_ids[0], C_ATTR_ACTIVE);//exit
				OSD_SetAttr(pHelp2Txt_ids[1], C_ATTR_INACTIVE);//edit
				OSD_SetAttr(pHelp2Txt_ids[2], C_ATTR_INACTIVE);//sort
				OSD_SetAttr(pHelp2Txt_ids[3], C_ATTR_INACTIVE);//setup
				OSD_SetAttr(pHelp2Txt_ids[4], C_ATTR_INACTIVE);//multi view
				break;
			case TITLE_VIDEO:
				OSD_SetAttr(pHelp1Txt_ids[0], C_ATTR_ACTIVE);//switch
				OSD_SetAttr(pHelp1Txt_ids[1], C_ATTR_INACTIVE);//edit
				OSD_SetAttr(pHelp1Txt_ids[2], C_ATTR_INACTIVE);//sort
				OSD_SetAttr(pHelp1Txt_ids[3], C_ATTR_INACTIVE);//repeat
				OSD_SetAttr(pHelp1Txt_ids[4], C_ATTR_ACTIVE);

				OSD_SetAttr(pHelp2Txt_ids[0], C_ATTR_ACTIVE);//exit
				OSD_SetAttr(pHelp2Txt_ids[1], C_ATTR_ACTIVE);
				OSD_SetAttr(pHelp2Txt_ids[2], C_ATTR_ACTIVE);
				OSD_SetAttr(pHelp2Txt_ids[3], C_ATTR_ACTIVE);
				OSD_SetAttr(pHelp2Txt_ids[4], C_ATTR_ACTIVE);
				break;
			case TITLE_RECORD:
				OSD_SetAttr(pHelp1Txt_ids[0], C_ATTR_ACTIVE);//switch
				OSD_SetAttr(pHelp1Txt_ids[1], C_ATTR_INACTIVE);//rename
				OSD_SetAttr(pHelp1Txt_ids[2], C_ATTR_INACTIVE);//lock
				OSD_SetAttr(pHelp1Txt_ids[3], C_ATTR_INACTIVE);//delete
				OSD_SetAttr(pHelp1Txt_ids[4], C_ATTR_ACTIVE);//

				OSD_SetAttr(pHelp2Txt_ids[0], C_ATTR_ACTIVE);//exit
				OSD_SetAttr(pHelp2Txt_ids[1], C_ATTR_ACTIVE);
				OSD_SetAttr(pHelp2Txt_ids[2], C_ATTR_ACTIVE);
				OSD_SetAttr(pHelp2Txt_ids[3], C_ATTR_ACTIVE);
				OSD_SetAttr(pHelp2Txt_ids[4], C_ATTR_ACTIVE);
				break;
			default:
				break;
			}
		}
		else
		{
			for(i = 0; i < help_cnt1[title_type];i++)
			{
				pTxt = pHelp1Txt_ids[i];
				OSD_SetAttr(pTxt, C_ATTR_ACTIVE);
			}

			for(i = 0; i < help_cnt2[title_type];i++)
			{
				pTxt = pHelp2Txt_ids[i];
				OSD_SetAttr(pTxt, C_ATTR_ACTIVE);
			}
		}
	}
	else //edit&advance help
	{
		if(OSD_GetFocusID(pObj) == MP_DEVICE_ID)
		{
			switch(title_type)
			{
			case TITLE_MUSIC:
			case TITLE_IMAGE:
			case TITLE_VIDEO:
				OSD_SetAttr(pHelp1Txt_ids[0], C_ATTR_INACTIVE);//rename
				OSD_SetAttr(pHelp1Txt_ids[1], C_ATTR_INACTIVE);//copy
				OSD_SetAttr(pHelp1Txt_ids[2], C_ATTR_INACTIVE);//delete
				OSD_SetAttr(pHelp1Txt_ids[3], C_ATTR_INACTIVE);//+folder
				OSD_SetAttr(pHelp1Txt_ids[4], C_ATTR_ACTIVE);//info
				break;
			case TITLE_RECORD:
				OSD_SetAttr(pHelp1Txt_ids[0], C_ATTR_INACTIVE);//copy
				OSD_SetAttr(pHelp1Txt_ids[1], C_ATTR_ACTIVE);//info
				OSD_SetAttr(pHelp1Txt_ids[2], C_ATTR_ACTIVE);//
				OSD_SetAttr(pHelp1Txt_ids[3], C_ATTR_ACTIVE);//
				OSD_SetAttr(pHelp1Txt_ids[4], C_ATTR_ACTIVE);//
				break;
			default:
				break;
			}

		}
		else
		{
			for(i = 0; i < edithelp_cnt[title_type];i++)
			{
				pTxt = pHelp1Txt_ids[i];
				OSD_SetAttr(pTxt, C_ATTR_ACTIVE);
			}
		}
	}
}

void win_set_mp_pvr_help(UINT8 main_help, TITLE_TYPE title_type)
{
	if(main_help == 1)
	{
		win_set_mpflielist_help1(helps1[title_type],help_cnt1[title_type]);
		win_set_mpflielist_help2(helps2[title_type],help_cnt2[title_type]);
	}
	else
	{
		win_set_mpflielist_help1(edithelps[title_type],edithelp_cnt[title_type]);
		win_set_mpflielist_help2(NULL,0);
	}
	win_set_mp_pvr_help_attr(main_help, title_type);
}

void win_draw_mp_pvr_help(void)
{
	POBJECT_HEAD pObj;

	pObj = (POBJECT_HEAD)&usb_help_win;
	OSD_DrawObject((POBJECT_HEAD)pObj,C_UPDATE_ALL);
}

///////////////////////////////////////
// end of title & help UI definition
///////////////////////////////////////


void win_get_fullname(char *fullname,char *path, char *name)
{
	STRCPY(fullname, path);
	strcat(fullname, "/");
	strcat(fullname, name);
}

void win_get_parent_dirname(char *parentpath,char *path)
{//get parent dir's path, as: /a/b/->/a/
	UINT16	i;

	STRCPY(parentpath, path);
	i = STRLEN(parentpath);
	while ((parentpath[i] != '/') && (i > 0))
	{
		i--;
	}
	if (i != 0)
	{
		parentpath[i] = '\0';
	}
	else
	{
		i += 1;
		parentpath[i] = '\0';
	}
}

#define FILE_EXT_NAME_SIZE 5
#define FILE_NAME_DISPLAY_MAXLEN 22 //for usb upgrade file name too long to system-down

void filter_unkownfont_name(const char *src_filename, char *display_filename)
{
	int i, j;

	for (i = 0, j = 0; src_filename[i] != '\0'; i++)
	{
		if ((src_filename[i] & 0x80) == 0x80)
		{
			if ((src_filename[i] & 0xc0) == 0xc0)
			{
				display_filename[j] = '-';
				j++;
			}
		}
		else
		{
			display_filename[j] = src_filename[i];
			j++;
		}
	}
	display_filename[j] = '\0';

	if (j > FILE_NAME_DISPLAY_MAXLEN)
	{
		for (i = j - 1; (display_filename[i] != '.') && (i >= 0); i--);
		if ((i < 0) || ((j - 1 - i) > FILE_NAME_DISPLAY_MAXLEN -FILE_EXT_NAME_SIZE))
		{
			//display_filename[FILE_NAME_DISPLAY_MAXLEN] = '\0';
			display_filename[FILE_NAME_DISPLAY_MAXLEN - 3] = '\0';
			strcat(display_filename, "...");
		}
		else
		{
			display_filename[FILE_NAME_DISPLAY_MAXLEN - (j - i) - 3] = '\0';
			strcat(display_filename, "...");
			strcat(display_filename, display_filename + i);
		}
	}

	return;
}

void win_shorten_filename(const char *src_filename, char *display_filename)
{
	int i, j;

	STRCPY(display_filename, src_filename);
	for (j = 0; display_filename[j] != '\0'; j++);

	if (j > FILE_NAME_DISPLAY_MAXLEN)
	{
		for (i = j - 1; (display_filename[i] != '.') && (i >= 0); i--);
		if ((i < 0) || ((j - 1 - i) > FILE_NAME_DISPLAY_MAXLEN -FILE_EXT_NAME_SIZE))
		{
			//display_filename[FILE_NAME_DISPLAY_MAXLEN] = '\0';
			display_filename[FILE_NAME_DISPLAY_MAXLEN - 3] = '\0';
			if((display_filename[FILE_NAME_DISPLAY_MAXLEN - 4] & 0xc0) == 0xc0)
			{
				display_filename[FILE_NAME_DISPLAY_MAXLEN - 4] = '\0';
			}
			strcat(display_filename, "...");
		}
		else
		{
			display_filename[FILE_NAME_DISPLAY_MAXLEN - (j - i) - 3] = '\0';
			if((display_filename[FILE_NAME_DISPLAY_MAXLEN - (j - i) - 4] & 0xc0) == 0xc0)
			{
				display_filename[FILE_NAME_DISPLAY_MAXLEN - (j - i) - 4] = '\0';
			}
			strcat(display_filename, "...");
			strcat(display_filename, display_filename + i);
		}
	}

	return;
}


void win_fill_filename(const char *src_filename, char *display_filename)
{
	int i, j;
	BOOL find_end_flg = FALSE;
	STRCPY(display_filename, src_filename);

	j = 0;
	while(j < FILE_NAME_DISPLAY_MAXLEN )
	{
		if(display_filename[j] == '\0')
		{
			find_end_flg = TRUE;
		}

		if(find_end_flg)
			{
			display_filename[j] = ' '; //Fill with Space
			}
		j++;
	}
	if(j > 0)
	{
		display_filename[j-1] = '\0';
	}
	else
		{
		display_filename[j] = '\0';
	}
	return;
}

RET_CODE win_get_display_dirname(char *display_dirname, char *src_dirname)
{
	char dirname1[FULL_PATH_SIZE];
	char dirname2[MAX_FILE_NAME_SIZE];
	char display_dirname2[MAX_FILE_NAME_SIZE];
	UINT16 i;

	if(!STRCMP(src_dirname, FS_ROOT_DIR))
	{
		STRCPY(display_dirname, "Root");
	}
	else
	{
		STRCPY(dirname1, "Root");
		strcat(dirname1, src_dirname+4);

		i = STRLEN(dirname1);
		while ((dirname1[i] != '/') && (i > 0))
		{
			i--;
		}
		if (i != 0)
		{
			STRCPY(dirname2, dirname1+i);
			//filter_unkownfont_name(dirname2,display_dirname2);//filter name that can not be show
			win_shorten_filename(dirname2,display_dirname2);
			dirname1[i] = '\0';
			//filter_unkownfont_name(dirname1,display_dirname);//filter name that can not be show
			win_shorten_filename(dirname1,display_dirname);
			strcat(display_dirname, display_dirname2);
		}
		else
		{
			//filter_unkownfont_name(dirname1,display_dirname);//filter name that can not be show
			win_shorten_filename(dirname1,display_dirname);
		}
	}
	return RET_SUCCESS;
}

UINT32 win_get_file_idx(FileListHandle file_list, char *file_name)
{
	UINT32 uIdx,uTotal;
	FileInfo file_node;
	char full_name[MAX_FILE_NAME_SIZE];
	unsigned int dir_num,file_num;

	get_file_list_info(file_list, &dir_num, &file_num, NULL);
	uTotal = dir_num+file_num;
	for(uIdx=0; uIdx<uTotal; uIdx++)
	{
		get_file_from_file_list(file_list, uIdx+1, &file_node);
		win_get_fullname(full_name, file_node.path, file_node.name);
		if(STRCMP(file_name, full_name) == 0)
			break;
	}
	if(uIdx == uTotal)
		uIdx = (UINT16)(~0);

	return uIdx;
}

BOOL win_check_openroot(FileListHandle file_list)
{
	char file_path[MAX_FILE_NAME_SIZE + 1];

	get_file_list_info(file_list, NULL, NULL, file_path);
	if(!STRCMP(file_path, FS_ROOT_DIR))
	{
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}


RET_CODE win_image_file_play(char *file, unsigned char rotate)
{
	int ret_val;
	struct image_slideshow_effect effect;

	effect.mode = osal_get_tick() % 5 + 1;
	switch(effect.mode)
	{
		case M_SHUTTERS:
			effect.mode_param.shuttles_param.direction = osal_get_tick() % 2;
			effect.mode_param.shuttles_param.time = 100;
			break;
		case M_BRUSH:
			effect.mode_param.brush_param.direction  = osal_get_tick() % 2;
			effect.mode_param.brush_param.time = 3;
			break;
		case M_SLIDE:
			effect.mode_param.slide_param.direction =  osal_get_tick() % 2;
			effect.mode_param.slide_param.time = 10;
			break;
		case M_RANDOM:
			effect.mode_param.random_param.type = osal_get_tick() % 3;
			effect.mode_param.random_param.time = 1;
			break;
		case M_FADE:
			effect.mode_param.fade_param.type = 0;
			effect.mode_param.fade_param.time = 0;
			break;
		default:
			break;
	}
	ret_val = image_decode_ex(file, IMAGEDEC_FULL_SRN, 0, 0, 720, 576, rotate, &effect);

	if(ret_val < 0)
	{
		return RET_FAILURE;
	}

	return RET_SUCCESS;
}

RET_CODE win_image_file_preview(char *file, RECT rect_info, int mode)
{
	int ret_val;

	ret_val = image_decode(file, mode, rect_info.left, rect_info.top, rect_info.right - rect_info.left, rect_info.bottom - rect_info.top, ANG_ORI);

	if(ret_val < 0)
	{
		return RET_FAILURE;
	}
	return RET_SUCCESS;
}

RET_CODE win_get_next_device(char *current_device, char *next_device, UINT8 fLeft)
{
	RET_CODE ret = RET_SUCCESS;
	char device_arry[MAX_DEVICE_NUM][3];
	UINT8 device_arry_size = MAX_DEVICE_NUM*3;
	UINT8 device_num;
	UINT8 i, next_device_idx;

	if(RET_FAILURE == get_current_stroage_device1(STORAGE_TYPE_ALL, device_arry, &device_arry_size))
	{
		return RET_FAILURE;
	}

	device_num = device_arry_size/3;
	for(i=0; i<device_num; i++)
	{
		if(strncmp(device_arry[i], current_device, 3) == 0)
			break;
	}

	if(fLeft == TRUE)
	{
		next_device_idx = (i+device_num-1)%device_num;
	}
	else
	{
		next_device_idx = (i+1)%device_num;
	}

	MEMCPY(next_device, device_arry[next_device_idx], 3);
	next_device[3] = '\0';

	return RET_SUCCESS;
}

void win_get_display_devicename(char *display_devicename, char *lib_devicename)
{
	char temp[2];

	if(strncmp(lib_devicename, "ud", 2) == 0)
	{
		STRCPY(display_devicename, "USB");
	}
	else if(strncmp(lib_devicename, "hd", 2) == 0)
	{
		STRCPY(display_devicename, "HDD");
	}
	else if(strncmp(lib_devicename, "sd", 2) == 0)
	{
		STRCPY(display_devicename, "SD");
	}
	else
	{
		STRCPY(display_devicename, "");
	}

	temp[0] = lib_devicename[2] - 'a' + '1';
	temp[1] = '\0';
	strcat(display_devicename, temp);
}

void win_set_device_icon(BITMAP *pBmp, char *lib_devicename)
{
	if(strncmp(lib_devicename, "ud", 2) == 0)
	{
		OSD_SetBitmapContent(pBmp, IM_MP3_ICON_MEM_USB);
	}
	else if(strncmp(lib_devicename, "hd", 2) == 0)
	{
		OSD_SetBitmapContent(pBmp, IM_MP3_ICON_MEM_HARDD);
	}
	else if(strncmp(lib_devicename, "sd", 2) == 0)
	{
		OSD_SetBitmapContent(pBmp, IM_MP3_ICON_MEM_SD);
	}
	else
	{
		OSD_SetBitmapContent(pBmp, 0);
	}
}

FileListType win_type_title2filelist(TITLE_TYPE title_type)
{
	FileListType list_type;

	switch(title_type)
	{
	case TITLE_MUSIC:
		list_type = MUSIC_FILE_LIST;
		break;
	case TITLE_IMAGE:
		list_type = IMAGE_FILE_LIST;
		break;
	case TITLE_VIDEO:
		list_type = VIDEO_FILE_LIST;
		break;
	default:
		list_type = MUSIC_FILE_LIST;
		break;
	}

	return list_type;
}

#ifndef __MM_FB5_Y_START_ADDR
#define __MM_FB5_Y_LEN          __MM_FB3_Y_LEN
#define __MM_FB5_C_LEN          __MM_FB3_C_LEN
#define __MM_FB6_Y_LEN          __MM_FB3_Y_LEN
#define __MM_FB6_C_LEN          __MM_FB3_C_LEN

#define __MM_FB5_Y_START_ADDR	((__MM_FB4_C_START_ADDR+__MM_FB4_C_LEN)&0XFFFFFE00)
#define __MM_FB5_C_START_ADDR   ((__MM_FB5_Y_START_ADDR+__MM_FB5_Y_LEN)&0XFFFFFE00)
#define __MM_FB6_Y_START_ADDR	((__MM_FB5_C_START_ADDR+__MM_FB5_C_LEN)&0XFFFFFE00)
#define __MM_FB6_C_START_ADDR   ((__MM_FB6_Y_START_ADDR+__MM_FB6_Y_LEN)&0XFFFFFE00)
#endif

static void config_deo_frm_buf(void)
{
	struct vpo_device *gpvpo_sd;
	Imagedec_frm deo_frm_buf[4];
	gpvpo_sd = gpvpo_sd = (struct vpo_device *)dev_get_by_id(HLD_DEV_TYPE_DIS, 1);
	if(NULL != gpvpo_sd)
	{
		deo_frm_buf[0].frm_y_addr = (UINT8 *)__MM_FB3_Y_START_ADDR;
		deo_frm_buf[0].frm_y_len = __MM_FB3_Y_LEN;
		deo_frm_buf[0].frm_c_addr = (UINT8 *)__MM_FB3_C_START_ADDR;
		deo_frm_buf[0].frm_c_len = __MM_FB3_C_LEN;
		deo_frm_buf[0].busy = 0;
		deo_frm_buf[1].frm_y_addr = (UINT8 *)__MM_FB4_Y_START_ADDR;
		deo_frm_buf[1].frm_y_len = __MM_FB4_Y_LEN;
		deo_frm_buf[1].frm_c_addr = (UINT8 *)__MM_FB4_C_START_ADDR;
		deo_frm_buf[1].frm_c_len = __MM_FB4_C_LEN;
		deo_frm_buf[1].busy = 0;
        deo_frm_buf[2].frm_y_addr = (UINT8 *)__MM_FB5_Y_START_ADDR;
        deo_frm_buf[2].frm_y_len = __MM_FB5_Y_LEN;
        deo_frm_buf[2].frm_c_addr = (UINT8 *)__MM_FB5_C_START_ADDR;
        deo_frm_buf[2].frm_c_len = __MM_FB5_C_LEN;
        deo_frm_buf[2].busy = 0;
        deo_frm_buf[3].frm_y_addr = (UINT8 *)__MM_FB6_Y_START_ADDR;
        deo_frm_buf[3].frm_y_len = __MM_FB6_Y_LEN;
        deo_frm_buf[3].frm_c_addr = (UINT8 *)__MM_FB6_C_START_ADDR;
        deo_frm_buf[3].frm_c_len = __MM_FB6_C_LEN;
        deo_frm_buf[3].busy = 0;
		imagedec_ioctl(1, IMAGEDEC_IO_CMD_CFG_DEO_FRM, (UINT32)(&deo_frm_buf));
	}
}

#ifdef _INVW_JUICE //v0.1.4
// Set the alternative media player callback handler
void win_media_network_player_set_alternative_callback(mp_callback_func mp_cb)
{
	if(mp_cb)
	{
		mp_alternative_cb = mp_cb;
	}
}


// Clear the alternative media player callback handler
void win_media_network_player_clear_alternative_callback(void)
{
	mp_alternative_cb = 0;
}


// Retrieve the alternative media player callback handler
mp_callback_func win_media_network_player_get_alternative_callback(void)
{
	return mp_alternative_cb;
}
#endif



#ifdef _INVW_JUICE
RET_CODE win_media_network_player_init(mp_callback_func mp_cb)
{
	RET_CODE ret = RET_SUCCESS;
	PeConfig pe_cfg;
    struct pe_video_cfg_extra video_cfg_extra;

	MEMSET(&pe_cfg, 0, sizeof(pe_cfg));
    MEMSET(&video_cfg_extra, 0, sizeof(struct pe_video_cfg_extra));

	//fill the music engine config
	#if 0//chunpin _INVW_JUICE
	pe_cfg.music.pcm_out_buff = __MM_TTX_BS_START_ADDR & 0x8fffffff;
	#else
//	pe_cfg.music.pcm_out_buff = (__MM_TTX_BS_START_ADDR & 0x8fffffff);
	pe_cfg.music.pcm_out_buff = (__MM_TTX_BS_START_ADDR & 0x8fffffff)+1;
	#endif
	pe_cfg.music.pcm_out_buff_size = __MM_TTX_BS_LEN & 0x8fffffff;
	pe_cfg.music.processed_pcm_buff = __MM_SUB_BS_START_ADDR & 0x8fffffff;
	pe_cfg.music.processed_pcm_buff_size = __MM_SUB_BS_LEN & 0x8fffffff;
	pe_cfg.music.mp_cb = mp_cb;

#ifdef _INVW_JUICE
	pe_cfg.music.pe_cache_buf_start_addr= 0;
	pe_cfg.music.pe_cache_buf_len= 0;
#endif

	//fill the image engine config
	pe_cfg.image.frm_y_size	= __MM_FB0_Y_LEN;
	pe_cfg.image.frm_y_addr	= __MM_FB0_Y_START_ADDR;
	pe_cfg.image.frm_c_size	= __MM_FB0_C_LEN;
	pe_cfg.image.frm_c_addr	= __MM_FB0_C_START_ADDR;
	pe_cfg.image.frm2_y_size = __MM_FB1_Y_LEN;
	pe_cfg.image.frm2_y_addr = __MM_FB1_Y_START_ADDR;
	pe_cfg.image.frm2_c_size = __MM_FB1_C_LEN;
	pe_cfg.image.frm2_c_addr = __MM_FB1_C_START_ADDR;
	pe_cfg.image.frm3_y_size = __MM_FB2_Y_LEN;
	pe_cfg.image.frm3_y_addr = __MM_FB2_Y_START_ADDR;
	pe_cfg.image.frm3_c_size = __MM_FB2_C_LEN;
	pe_cfg.image.frm3_c_addr = __MM_FB2_C_START_ADDR;
	pe_cfg.image.decoder_buf = (UINT8 *)__MM_MP_BUFFER_ADDR;
	pe_cfg.image.decoder_buf_len = __MM_MP_BUFFER_LEN;
	pe_cfg.image.mp_cb = mp_cb;

	//fill the video engine config
	pe_cfg.video.mp_cb = mp_cb;
	pe_cfg.video.decoder_buf = __MM_VIDEO_FILE_BUF_ADDR;
	pe_cfg.video.decoder_buf_len = __MM_VIDEO_FILE_BUF_LEN;
	pe_cfg.video.mm_vbv_len = __MM_VBV_LEN;
	pe_cfg.video.reserved = 0;
#if 1//chunpin _INVW_JUICE
    	pe_cfg.video.disable_seek = TRUE;//disable network mediaplay seek function
#endif

#ifdef M36F_CHIP_MODE
#if (SYS_SDRAM_SIZE == 128 || SYS_SDRAM_SIZE == 64)
    // video file buffer is seperated with frame buffer
    #if (__MM_FB_TOP_ADDR > __MM_VIDEO_FILE_BUF_ADDR)
    pe_cfg.video.decoder_buf_len = __MM_FB_TOP_ADDR - __MM_VIDEO_FILE_BUF_ADDR;
    #endif
    video_cfg_extra.frame_buf_base = __MM_FB_BOTTOM_ADDR;
    video_cfg_extra.frame_buf_len = __MM_FB_TOP_ADDR - __MM_FB_BOTTOM_ADDR;
    video_cfg_extra.reserved[0] = (UINT32)font_array_1bit_subt;
    video_cfg_extra.reserved[1] = 7; //sizeof(font_array_1bit_subt) / sizeof(font_array_1bit_subt[0]);
    #ifdef SUPPORT_CAS9
    video_cfg_extra.frame_buf_base = (__MM_EPG_BUFFER_START+0xfff)&0xfffff000;
    video_cfg_extra.frame_buf_len = __MM_FB_TOP_ADDR - video_cfg_extra.frame_buf_base;
    video_cfg_extra.reserved[2] = video_cfg_extra.frame_buf_base;
    video_cfg_extra.reserved[3] = video_cfg_extra.frame_buf_len;
    #ifdef SD_PVR
	video_cfg_extra.reserved[4] = (720<<16)|(576);  //OSD:720*576
    #endif
    #endif
    pe_cfg.video.reserved = (UINT32)(&video_cfg_extra);
#endif
#else
    // M3602
    // video file buffer is seperated with frame buffer
    video_cfg_extra.frame_buf_base = __MM_FB_BOTTOM_ADDR;
    video_cfg_extra.frame_buf_len = __MM_FB_TOP_ADDR - __MM_FB_BOTTOM_ADDR;
    video_cfg_extra.reserved[0] = font_array_1bit_subt;
    video_cfg_extra.reserved[1] = 7; //sizeof(font_array_1bit_subt) / sizeof(font_array_1bit_subt[0]);
    pe_cfg.video.reserved = (UINT32)(&video_cfg_extra);
#endif

	ret = media_player_init(&pe_cfg);
	config_deo_frm_buf();
	return ret;
}

#endif
RET_CODE win_media_player_init(mp_callback_func mp_cb)
{
	RET_CODE ret = RET_SUCCESS;
	PeConfig pe_cfg;
    struct pe_video_cfg_extra video_cfg_extra;

	MEMSET(&pe_cfg, 0, sizeof(pe_cfg));
    MEMSET(&video_cfg_extra, 0, sizeof(struct pe_video_cfg_extra));

	//fill the music engine config
	pe_cfg.music.pcm_out_buff = __MM_TTX_BS_START_ADDR & 0x8fffffff;
	pe_cfg.music.pcm_out_buff_size = __MM_TTX_BS_LEN & 0x8fffffff;
	pe_cfg.music.processed_pcm_buff = __MM_SUB_BS_START_ADDR & 0x8fffffff;
	pe_cfg.music.processed_pcm_buff_size = __MM_SUB_BS_LEN & 0x8fffffff;
	pe_cfg.music.mp_cb = mp_cb;
	pe_cfg.music.pe_cache_buf_start_addr= 0;
	pe_cfg.music.pe_cache_buf_len= 0;

	//fill the image engine config
	pe_cfg.image.frm_y_size	= __MM_FB0_Y_LEN;
	pe_cfg.image.frm_y_addr	= __MM_FB0_Y_START_ADDR;
	pe_cfg.image.frm_c_size	= __MM_FB0_C_LEN;
	pe_cfg.image.frm_c_addr	= __MM_FB0_C_START_ADDR;
	pe_cfg.image.frm2_y_size = __MM_FB1_Y_LEN;
	pe_cfg.image.frm2_y_addr = __MM_FB1_Y_START_ADDR;
	pe_cfg.image.frm2_c_size = __MM_FB1_C_LEN;
	pe_cfg.image.frm2_c_addr = __MM_FB1_C_START_ADDR;
	pe_cfg.image.frm3_y_size = __MM_FB2_Y_LEN;
	pe_cfg.image.frm3_y_addr = __MM_FB2_Y_START_ADDR;
	pe_cfg.image.frm3_c_size = __MM_FB2_C_LEN;
	pe_cfg.image.frm3_c_addr = __MM_FB2_C_START_ADDR;
	#ifdef DUAL_ENABLE
	pe_cfg.image.decoder_buf = (UINT8 *)__MM_MP_BUFFER_ADDR;
	pe_cfg.image.decoder_buf_len = __MM_MP_BUFFER_LEN;
	#else
	pe_cfg.image.decoder_buf = (UINT8 *)__MM_TTX_BS_START_ADDR+__MM_TTX_BS_LEN;
	pe_cfg.image.decoder_buf_len = __MM_MP_BUFFER_ADDR+__MM_MP_BUFFER_LEN -__MM_TTX_BS_START_ADDR-__MM_TTX_BS_LEN;
	#endif
	pe_cfg.image.mp_cb = mp_cb;

	//fill the video engine config
	pe_cfg.video.mp_cb = mp_cb;
	pe_cfg.video.decoder_buf = __MM_VIDEO_FILE_BUF_ADDR;
	pe_cfg.video.decoder_buf_len = __MM_VIDEO_FILE_BUF_LEN;
	pe_cfg.video.mm_vbv_len = __MM_VBV_LEN;
	pe_cfg.video.reserved = 0;
    	pe_cfg.video.disable_seek = TRUE;//disable network mediaplay seek function

#ifdef M36F_CHIP_MODE
#if (SYS_SDRAM_SIZE == 128 || SYS_SDRAM_SIZE == 64)
    // video file buffer is seperated with frame buffer
    #if (__MM_FB_TOP_ADDR > __MM_VIDEO_FILE_BUF_ADDR)
    pe_cfg.video.decoder_buf_len = __MM_FB_TOP_ADDR - __MM_VIDEO_FILE_BUF_ADDR;
    #endif
    video_cfg_extra.frame_buf_base = __MM_FB_BOTTOM_ADDR;
    video_cfg_extra.frame_buf_len = __MM_FB_TOP_ADDR - __MM_FB_BOTTOM_ADDR;
    video_cfg_extra.reserved[0] = (UINT32)font_array_1bit_subt;
    video_cfg_extra.reserved[1] = 8/*7*/; // 131128//sizeof(font_array_1bit_subt) / sizeof(font_array_1bit_subt[0]);	//Robin
    #ifdef SUPPORT_CAS9
    video_cfg_extra.frame_buf_base = (__MM_EPG_BUFFER_START+0xfff)&0xfffff000;
    video_cfg_extra.frame_buf_len = __MM_FB_TOP_ADDR - video_cfg_extra.frame_buf_base;
    video_cfg_extra.reserved[2] = video_cfg_extra.frame_buf_base;
    video_cfg_extra.reserved[3] = video_cfg_extra.frame_buf_len;
    #ifdef SD_PVR
	video_cfg_extra.reserved[4] = (720<<16)|(576);  //OSD:720*576
    #endif
    #endif
    //pe_cfg.video.reserved = (UINT32)(&video_cfg_extra);
#endif
#else
    // M3602
    // video file buffer is seperated with frame buffer
    video_cfg_extra.frame_buf_base = __MM_FB_BOTTOM_ADDR;
    video_cfg_extra.frame_buf_len = __MM_FB_TOP_ADDR - __MM_FB_BOTTOM_ADDR;
    video_cfg_extra.reserved[0] = font_array_1bit_subt;
    video_cfg_extra.reserved[1] = 7; //sizeof(font_array_1bit_subt) / sizeof(font_array_1bit_subt[0]);
    //pe_cfg.video.reserved = (UINT32)(&video_cfg_extra);
#endif

#ifdef IMG_2D_TO_3D
    pe_cfg.image.ALi_pic_2dto3d = ALi_pic_2dto3d;
#ifndef DUAL_ENABLE   // 3811 64M memory location
#ifdef _SUPPORT_64M_MEM
    pe_cfg.image.decoder_buf = (UINT8 *)__MM_TTX_BS_START_ADDR+__MM_TTX_BS_LEN;
	pe_cfg.image.decoder_buf_len = __MM_FB_BOTTOM_ADDR + 0xD00000 -__MM_TTX_BS_START_ADDR-__MM_TTX_BS_LEN;
    //video_cfg_extra.frame_buf_base = __MM_FB2_C_START_ADDR + __MM_FB2_C_LEN;//__MM_FB_BOTTOM_ADDR;
    //video_cfg_extra.frame_buf_len = __MM_FB_TOP_ADDR - __MM_FB2_C_START_ADDR - __MM_FB2_C_LEN;//__MM_FB_BOTTOM_ADDR;
#endif
#endif
#endif

    pe_cfg.video.reserved = (UINT32)(&video_cfg_extra);
	ret = media_player_init(&pe_cfg);
	config_deo_frm_buf();
	return ret;
}



void file_list_init_parameter()
{
//	mp_udisk_cnt = get_stroage_device_number(STORAGE_TYPE_ALL);
#ifdef DVR_PVR_SUPPORT
//	udisk_set_ingore_dir(PVR_ROOT_DIR);
#endif
//	playlist_readfromdisk(MP_MUSIC);
//	playlist_readfromdisk(MP_PICTURE);
	init_usblist_param();
//	MEMSET(m_mp_last_access_device, 0xff, sizeof(m_mp_last_access_device));
}


BOOL win_check_del_flag(UINT32 *pdel_array, UINT32 index)
{
	UINT32	wIndex;
	UINT8	bShiftBit;

	wIndex		= index/32;
	bShiftBit	= (UINT8)(index%32);

	if((pdel_array[wIndex])&(0x00000001<<bShiftBit))
		return TRUE;
	else
		return FALSE;
}

BOOL win_check_del_flags(UINT32 *pdel_array, UINT32 array_size)
{
	OBJLIST* ol;
	UINT32 i,n;

	n = array_size/32;	/* current playlist totoa number */

	for(i=0;i<n;i++)
		if(pdel_array[i]>0)	return TRUE;

	for(i=n*32; i< array_size; i++)
		if(win_check_del_flag(pdel_array, i))
			return TRUE;

	return FALSE;
}

void win_switch_del_flag(UINT32 *pdel_array, UINT32 index)
{
	UINT32	wIndex;
	UINT8	bShiftBit;

	wIndex		= index/32;
	bShiftBit	= index%32;
	pdel_array[wIndex] ^= (0x00000001<<bShiftBit);
}

void win_clear_del_flags(UINT32 *pdel_array, UINT32 array_size)
{
	UINT32 i,n;

	n = array_size/sizeof(pdel_array[0]);
	for(i=0;i<n;i++)
		pdel_array[i] = 0;
}

void win_set_del_flags(UINT32 *pdel_array, UINT32 array_size)
{
	UINT32 i,n;

	n = array_size/sizeof(pdel_array[0]);
	for(i=0;i<n;i++)
		pdel_array[i] = (UINT32)(~0);
}

#endif

